import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {ButtonSizeType} from '../../../enums';

@Component({
  selector: 'dhl-action',
  templateUrl: './dhl-action.component.html',
})
export class DhlActionComponent implements OnInit {

  sizeType = ButtonSizeType.SMALL;
  @Input() name;
  @Input() icon;
  @Input() show = true;
  @Input() disable = false;

  /**
   * 根据每行数据判断是否显示这个按钮
   */
  @Input() set showFun(value) {
    $(this.htmlElementRef.nativeElement).data('showFun', value);
  }

  /**
   * 根据每行数据判断是否disable这个按钮
   */
  @Input() set disableFun(value) {
    $(this.htmlElementRef.nativeElement).data('disableFun', value);
  }


  /**
   * 是否让按钮处于加载的状态
   *
   */
  @Input() set loadBtnIndex(value) {
    const loading = $(this.htmlElementRef.nativeElement)
      .parents('#table-config')
      .next('div.dhl-table')
      .data('uploadBtnLoading');
    if (loading) {
      loading(this.name, value);
    }
  }


  @ViewChild('htmlElement', {static: true, read: ElementRef}) htmlElementRef: ElementRef;

  @Output() buttonClick = new EventEmitter();

  ngOnInit() {
  }

  actionClick(obj) {
    this.buttonClick.emit(obj);
  }


}





